package sis.util;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-08-03 11:06
* @notify 
* @version 1.0
*/

import java.util.*;

public class EventMap <K extends Date,V>extends MultiHashMap<K,V>  {

    //获取过去时间的存储的事件
    public List<V> getPastEvents(){
       List<V> events = new ArrayList<V>();
       //遍历键值映射set
       for(Map.Entry<K,List<V>>entry:entrySet()){
           //获取key
           K date = entry.getKey();
           if(hasPassed(date)){
               events.addAll(entry.getValue());
           }
       }
       return events;
    }

    private boolean hasPassed(K date){
        //创建日历
        Calendar when = new GregorianCalendar();
        //设置时间
        when.setTime(date);
        //创建日历,空的构造子为当前时间
        Calendar today = new GregorianCalendar();
        //如果传入的年不等于今年
        if(when.get(Calendar.YEAR)!=today.get(Calendar.YEAR)){
            //比较年份
            return when.get(Calendar.YEAR)<today.get(Calendar.YEAR);
        }
        //比较 日
        return when.get(Calendar.DAY_OF_YEAR)<today.get(Calendar.DAY_OF_YEAR);
    }
}
